package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Manage;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * Servlet implementation class AddTeacher
 */
@WebServlet("/AddTeacher")

public class AddTeacher extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddTeacher() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//doGet(request, response);
		request.setCharacterEncoding("utf-8");
		String tea_name =  request.getParameter("tea_name");
		String tea_sex =  request.getParameter("tea_sex");
		String tea_id =  request.getParameter("tea_id");
		System.out.println(tea_name);
		System.out.println(tea_sex);
		Manage man = new Manage();
		String waring = null;
		try {
			waring = man.AddTeacher(tea_name ,tea_sex ,tea_id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out= response.getWriter();
		JSONArray jsons=new JSONArray();
		JSONObject json=new JSONObject();
		json.put("waring", waring);
		jsons.add(json);
		System.out.println(jsons.toString());
		out.println(jsons.toString());
		out.flush();
		out.close();
	}

}
